<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    .box {
        position: absolute;
        top: 100px;
        left: 0px;
        width: 50px;
        height: 50px;
       
        background-color: black;
    }
</style>
<script>
window.onload=function(){
    var a1=document.querySelector('button')
    var a2=document.querySelector('div')//选中（）内的
    var moveVal = 0;
            var timer = null;
            a1.onclick = function(){
                clearInterval(timer)
                timer=setInterval(()=>{
                    //名称=定时器
                    moveVal+=3;
                    //距离每三十毫秒加三
                    a2.style.left=moveVal+"px"
                    //给box加css样式
                },30)//定时器，每30毫秒运行一次
            }
        }
</script>
<body>
    <button>点我</button>
    <div class="box">

    </div>
</body>

</html>